from math import sqrt

a = int(input('Введите четырехзначное натуральное число:')) 
b = a // 1000
c = a // 100 % 10
d = a % 100 // 10
e = a % 10
bc = b * 10 + c
cd = c * 10 + d
de = d * 10 + e
bcd = b * 100 + c * 10 + d
cde = c * 100 + d * 10 + e
b = b
c = c
d = d
e = e
a = a

B = [a, b, bc, bcd, c, cd, cde, d, de, e]
C = [] 
for i in B:
    prime = True
    m = 2
    while m <= sqrt(i):
        if i % m == 0:
            prime = False
            break
        m += 1  
    if prime:
        C.append(i)

if len(C) > 0:
    print(max(C))
else:
    print('0')
